import 'package:flutter/material.dart';
import 'package:flutter_common/ui/scaffold.dart';
import 'package:flutter_common/ui/widget/scroll_page_view.dart';

class ScrollPageDemo extends StatefulWidget {

  @override
  State<StatefulWidget> createState() => _state();

}

class _state extends State<ScrollPageDemo> {
  int curIndex = 0;
  List pages = [OnePage(), TwoPage()];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: FxAppBar(
        title: "ScrollPage",
      ),
      body: pages[curIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: curIndex,
        onTap: (i) {
          setState(() {
            curIndex = i;
          });
        },
        items: const [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: "home"),
          BottomNavigationBarItem(icon: Icon(Icons.add), label: "add"),
        ],
      ),
    );
  }
}

class OnePage extends StatelessWidget {

  List<String> imgs = ["cat.jpg", "horse.jpg", "road.jpg", "sea.png","star.jpg"];

  @override
  Widget build(BuildContext context) {
    return AspectRatio(aspectRatio: 16/9, child: ScrollPageView(
      children: imgs.map((e) => Image.asset("imgs/$e")).toList(),
    ));
  }
}

class TwoPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Text("data");
  }

}